import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/views/login'
import Layout from '@/views/layout/layout'

Vue.use(Router)

/**
 * alwaysShow: true           if set true, will always show the root menu, whatever its child routes length
 *                            if not set alwaysShow, only more than ont route under the children
 *                            it will becomes nested mode, otherwise not show the root menu
 * alwaysShow: true           如果设置为true,它将总是现在在根目录。如果不设置的话，当它只有1个子路由的时候，会把
 *                            它的唯一子路由放到跟目录上来，而不显示它自己本身。
 */

export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: Login,
    meta: {
      title: '登录'
    }
  },
  {
    path: '/admin_manage',
    component: Layout,
    redirect: '/admin_manage/index',
    // alwaysShow: true,
    meta: {
      icon: 'users',
      title: '管理员设置'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/admin-manage/admin_manage')
      }
    ]
  },
  {
    path: '/employee_apply',
    component: Layout,
    redirect: '/employee_apply/index',
    // alwaysShow: true,
    meta: {
      icon: 'drivers-license',
      title: '业务员申请'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/employee-manage/employee_apply')
      }
    ]
  },
  {
    path: '/employee_manage',
    component: Layout,
    redirect: '/employee_manage/index',
    // alwaysShow: true,
    meta: {
      icon: 'address-card-o',
      title: '业务员管理'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/employee-manage/employee_manage')
      }
    ]
  },
  {
    path: '/product_manage',
    component: Layout,
    redirect: '/product_manage/index',
    meta: {
      icon: 'shopping-bag',
      title: '产品管理'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/product-manage/product_manage')
      }
    ]
  },
  {
    path: '/order_check',
    redirect: '/order_check/index',
    component: Layout,
    meta: {
      icon: 'newspaper-o',
      title: '订单检验'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/order-check/order-check')
      }
    ]
  },
  {
    path: '/order_manage',
    redirect: '/order_manage/index',
    component: Layout,
    meta: {
      icon: 'shopping-cart',
      title: '订单管理'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/order-manage/order_manage')
      }
    ]
  },

  {
    path: '/promotion-manage',
    component: Layout,
    meta: {
      icon: 'send',
      title: '推广管理'
    },
    redirect: '/promotion-manage/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/promotion-manage/promotion_manage')
      }
    ]
  },
  {
    path: '/credit-manage',
    component: Layout,
    meta: {
      icon: 'envira',
      title: '积分兑换'
    },
    redirect: '/credit-manage/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/credit-manage/credit_manage')
      }
    ]
  },
  {
    path: '/customer-manage',
    component: Layout,
    meta: {
      icon: 'user-secret',
      title: '客户管理'
    },
    redirect: '/customer-manage/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/customer-manage/customer-manage')
      }
    ]
  },
  {
    path: '/enterprise-manage',
    component: Layout,
    meta: {
      icon: 'user-secret',
      title: '企业信息管理'
    },
    redirect: '/enterprise-manage/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/enterprise-manage/enterprise_manage')
      }
    ]
  },
  {
    path: '/company-manage',
    component: Layout,
    meta: {
      icon: 'home',
      title: '企业信息'
    },
    redirect: '/company-manage/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/company-manage/company-manage')
      }
    ]
  }
]

export default new Router({
  // mode: 'history',  require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    alwaysShow: true,
    meta: {
      title: '表格',
      icon: 'edit'
    },
    children: [
      {
        path: 'export-excel',
        name: '导出表格',
        component: () => import('@/views/excel/export-excel'),
        meta: { icon: 'arrow-left', title: 'exportExcel' }
      },
      {
        path: 'upload-excel',
        name: '上传表格',
        component: () => import('@/views/excel/upload-excel'),
        meta: { icon: 'minus', title: 'uploadExcel' }
      }
    ]
  },
  {
    path: '/clipboard',
    component: Layout,
    redirect: 'index',
    meta: {
      icon: 'document',
      title: '剪切板'
    },
    children: [
      {
        path: 'index',
        name: 'clipBoard',
        component: () => import('@/views/clipboard'),
        meta: { title: '剪切板示例', icon: 'document' }
      }
    ]
  }
]
